//
//  OrderStatusTableViewCell.swift
//  DiDiRecycle
//
//  Created by abb on 16/8/9.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class OrderStatusTableViewCell: UITableViewCell {
    
    var status:Int? {
        didSet {
            if status != nil {
                if status > 2 {// 订单完成
                    return
                }
                if status > 1 {// 商家已回收
                    thirdLabel.textColor = UIColor.tintColor()
                    thirdPoint.backgroundColor = UIColor.tintColor()
                    splitLineRight.backgroundColor = UIColor.tintColor()
                }
                if status > 0 {// 商家已接单
                    secondLabel.textColor = UIColor.tintColor()
                    secondPoint.backgroundColor = UIColor.tintColor()
                    splitLineLeft.backgroundColor = UIColor.tintColor()
                }
                // 订单已提交
                firstPoint.backgroundColor = UIColor.tintColor()
                firstLabel.textColor = UIColor.tintColor()
            }
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        
    }
    
    private func setupUI() {
        // 添加子控件
        addSubview(firstPoint)
        addSubview(splitLineLeft)
        addSubview(secondPoint)
        addSubview(splitLineRight)
        addSubview(thirdPoint)
        addSubview(firstLabel)
        addSubview(secondLabel)
        addSubview(thirdLabel)
        // 布局子控件
        firstPoint.snp_makeConstraints { (make) in
            make.centerX.equalTo(self).multipliedBy(0.25)
            make.centerY.equalTo(self).offset(5)
            make.size.equalTo(CGSize(width: 5, height: 5))
        }
        secondPoint.snp_makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(5)
            make.size.equalTo(CGSize(width: 5, height: 5))
        }
        thirdPoint.snp_makeConstraints { (make) in
            make.centerX.equalTo(self).multipliedBy(1.75)
            make.centerY.equalTo(self).offset(5)
            make.size.equalTo(CGSize(width: 5, height: 5))
        }
        splitLineLeft.snp_makeConstraints { (make) in
            make.centerY.equalTo(firstPoint)
            make.left.equalTo(firstPoint.snp_right).offset(10)
            make.right.equalTo(secondPoint.snp_left).offset(-10)
            make.height.equalTo(0.5)
        }
        splitLineRight.snp_makeConstraints { (make) in
            make.centerY.equalTo(secondPoint)
            make.left.equalTo(secondPoint.snp_right).offset(10)
            make.right.equalTo(thirdPoint.snp_left).offset(-10)
            make.height.equalTo(0.5)
        }
        firstLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(firstPoint)
            make.bottom.equalTo(firstPoint.snp_top).offset(-10)
        }
        secondLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(secondPoint)
            make.bottom.equalTo(secondPoint.snp_top).offset(-10)
        }
        thirdLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(thirdPoint)
            make.bottom.equalTo(thirdPoint.snp_top).offset(-10)
        }
    }
    
    // MARK: - 懒加载
    
    
    /// 第一个点
    private lazy var firstPoint:PointView = PointView()
    /// 分割线左
    private lazy var splitLineLeft:UIView = UIView.splitLine(UIColor.grayColor())
    /// 第二个点
    private lazy var secondPoint:PointView = PointView()
    /// 分割线右
    private lazy var splitLineRight:UIView = UIView.splitLine(UIColor.grayColor())
    /// 第三个点
    private lazy var thirdPoint:PointView = PointView()
    
    private lazy var firstLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.grayColor(), fontSize: 12)
        label.text = "订单已提交"
        return label
    }()
    
    private lazy var secondLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.grayColor(), fontSize: 12)
        label.text = "商家已接单"
        return label
    }()
    private lazy var thirdLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.grayColor(), fontSize: 12)
        label.text = "商家已回收"
        return label
    }()

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

class PointView:UIView {
    init() {
        super.init(frame: CGRectZero)
        layer.cornerRadius = 2.5
        backgroundColor = UIColor.grayColor()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}